<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<jsp:include page="../header.jsp" />
<script>
	$(function() {
		$(document).ready(function(){
			if(${!user.admin}){
				$('#adminField').hide();
				$('#adminField2').hide();
			}
			$('#datepicker').datepicker();
		});
	});
	function showHide(){
		$(function(){
			if($('#isAdmin').is(':checked')){
				$('#adminField').show();
				$('#adminField2').show();
			}else{
				$('#adminField').hide();
				$('#adminField2').hide();
			}
		});
	}
</script>
<div id="content">
	<div id="topstory" class="box">
		<h1>
			<fmt:message key="user.title.new" />
		</h1>
	</div>
	<div class="padding">
		<c:choose>
			<c:when test="${ user != null}">
				<c:if test="${not empty formErrors}">
					<div class="ui-widget">
						<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
							<c:forEach var="error" items="${formErrors }">
								<p>
									<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span> <strong>Error:</strong>
									<c:out value="${error.message}" />
								</p>
							</c:forEach>
						</div>
					</div>
				</c:if>
				<form:form action="submit.do" commandName="userView" method="POST">
					<table border="0" cellspacing="5" cellpadding="0" width="100%" class="formTable tplBorder">
						<tr>
							<td width="15%"></td>
							<td width="35%"></td>
							<td width="15%"></td>
							<td width="35%"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.admin" /></td>
							<td><form:checkbox id="isAdmin" path="admin" onclick="javascript: showHide();" value="true" /> <form:errors path="admin" /></td>
							<td colspan="2" />
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.name" /></td>
							<td><form:input path="jmeno" /> <form:errors path="jmeno" cssStyle="color: red;" /></td>
							<td class="label"><fmt:message key="user.surname" /></td>
							<td><form:input path="prijmeni" /> <form:errors path="prijmeni" cssStyle="color: red;" /></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.login" /></td>
							<td><form:input path="login" /> <form:errors path="login" cssStyle="color: red;" /></td>
							<td class="label"><fmt:message key="user.password" /></td>
							<td><form:input path="password" /> <form:errors path="password" cssStyle="color: red;" /></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.street" /></td>
							<td><form:input path="ulice" /> <form:errors path="ulice" cssStyle="color: red;" /></td>
							<td colspan="2">
						</tr>
						<tr>
							<td class="label"><fmt:message key="user.mesto" /></td>
							<td><form:input path="mesto" /> <form:errors path="mesto" cssStyle="color: red;" /></td>
							<td class="label"><fmt:message key="user.psc" /></td>
							<td><form:input path="psc" /> <form:errors path="psc" cssStyle="color: red;" /></td>
						</tr>
						<tr id="adminField">
							<td class="label"><fmt:message key="user.rodne.cislo" /></td>
							<td><form:input path="rodneCislo" /> <form:errors path="rodneCislo" cssStyle="color: red;" /></td>
							<td colspan="2" />
						</tr>
						<tr id="adminField2">
							<td class="label"><fmt:message key="user.plat" /></td>
							<td><form:input path="plat" /> <form:errors path="plat" cssStyle="color: red;" /></td>
							<td colspan="2" />
						</tr>
						<tr>
							<td colspan="2"><input type="submit" /></td>
							<td colspan="2"><input type="button" onclick="javascript:window.location = '../users.do'" value="Back To List" /></td>
						</tr>
					</table>
				</form:form>
			</c:when>
			<c:otherwise>
				<h3>${error }</h3>
			</c:otherwise>
		</c:choose>
	</div>
	<!-- /padding -->
</div>
<!-- /content -->
<jsp:include page="side-menu.jsp" />
<jsp:include page="../foother.jsp" />
